package com.hackerrank.contests.july13.challenges.ultimatetictactoe;

import java.util.Scanner;

public class Solution {
	private static Move m;
	private static class Move {
		int ur, uc, r, c;
		public Move(int ur, int uc, int r, int c) {
			this.ur = ur;
			this.uc = uc;
			this.r = r;
			this.c = c;
		}
		public String toString() {
			return ur + " " + uc + " " + r + " " + c;
		}
	}
	private static boolean isWon(char[][] b, int ur, int uc) {
		for(int r = 0; r < 3; r++)
			if(b[ur * 3 + r][uc * 3] != '-' && b[ur * 3 + r][uc * 3] == b[ur * 3 + r][uc * 3 + 1] && b[ur * 3 + r][uc * 3 + 1] == b[ur * 3 + r][uc * 3 + 2])
				return true;
		for(int c = 0; c < 3; c++)
			if(b[ur * 3][uc * 3 + c] != '-' && b[ur * 3][uc * 3 + c] == b[ur * 3 + 1][uc * 3 + c] && b[ur * 3 + 1][uc * 3 + c] == b[ur * 3 + 2][uc * 3 + c])
				return true;
		if(b[ur * 3][uc * 3] != '-' && b[ur * 3][uc * 3] == b[ur * 3 + 1][uc * 3 + 1] && b[ur * 3 + 1][uc * 3 + 1] == b[ur * 3 + 2][uc * 3 + 2])
			return true;
		if(b[ur * 3][uc * 3 + 2] != '-' && b[ur * 3][uc * 3 + 2] == b[ur * 3 + 1][uc * 3 + 1] && b[ur * 3 + 1][uc * 3 + 1] == b[ur * 3 + 2][uc * 3])
			return true;
		return false;
	}
	private static boolean isWon(char[][] b) {
		for(int r = 0; r < 3; r++)
			if(isWon(b, r, 0) && isWon(b, r, 1) && isWon(b, r, 2))
				return true;
		for(int c = 0; c < 3; c++)
			if(isWon(b, 0, c) && isWon(b, 1, c) && isWon(b, 2, c))
				return true;
		if(isWon(b, 0, 0) && isWon(b, 1, 1) && isWon(b, 2, 2))
			return true;
		if(isWon(b, 0, 2) && isWon(b, 1, 1) && isWon(b, 2, 0))
			return true;
		return false;
	}
	private static char opponent(char p) {
		if(p == 'O')
			return 'X';
		return 'O';
	}
	private static boolean moveu(char p, int ur, int uc, char[][] b) {
		if(ur >= 0 && !isWon(b, ur, uc))
			return move(p, ur, uc, b);
		for(ur = 0; ur < 3; ur++)
			for(uc = 0; uc < 3; uc++)
				if(!isWon(b, ur, uc) && move(p, ur, uc, b))
					return true;
		return false;
	}
	private static boolean move(char p, int ur, int uc, char[][] b) {
		for(int r = 0; r < 3; r++)
			for(int c = 0; c < 3; c++)
				if(b[ur * 3 + r][uc * 3 + c] == '-') {
					m = new Move(ur, uc, r, c);
					return true;
//					b[ur * 3 + r][uc * 3 + c] = p;
//					if(isWon(b) || !moveu(opponent(p), r, c, b)) {
//						b[ur * 3 + r][uc * 3 + c] = '-';
//						return true;
//					}
//					b[ur * 3 + r][uc * 3 + c] = '-';
				}
		return false;
	}
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		char p = in.nextLine().charAt(0);
		int ur = in.nextInt(), uc = in.nextInt();
		in.nextLine();
		char[][] b = new char[9][9];
		for(int r = 0; r < 9; r++)
			b[r] = in.nextLine().toCharArray();
		moveu(p, ur, uc, b);
		System.out.println(m);
	}
}
